<?php

declare(strict_types = 1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\JsonRpc\CalculatorServiceConsumer;
use App\Model\User;
use App\Request\FooRequest;
use Hyperf\Di\Annotation\Inject;
use JetBrains\PhpStorm\ArrayShape;

class IndexController extends Controller
{
    #[Inject]
    protected CalculatorServiceConsumer $calculatorServiceConsumer;

    #[ArrayShape(['code' => "int", 'data' => "int"])]
    public function index(): array
    {
        return ['code' => 200, 'data' => $this->calculatorServiceConsumer->add(2, 3)];
    }

    #[ArrayShape(['code' => "int", 'data' => "int"])]
    public function test(): array
    {
        return [
            'code' => 200,
            'data' => $this->calculatorServiceConsumer->handle([
                'list'  => [],
                'count' => []
            ])
        ];
    }

    #[ArrayShape(['code' => "int", 'data' => "\Hyperf\Database\Model\Collection"])]
    public function es(): array
    {
        //        User::where(['status' => 1])->searchable();
        return [
            'code' => 200,
            'data' => User::search('18')->where('status', '1')->get()
        ];
    }

    public function validate(FooRequest $request): array
    {
        $validated = $request->validated();
        return [];
    }
}
